package com.gzh.teaching.controller;

import com.gzh.core.model.vo.Result;
import com.gzh.core.service.CheckToken;
import com.gzh.core.util.RequestContextUtil;
import com.gzh.teaching.model.vo.CommentParam;
import com.gzh.teaching.model.vo.CommentResult;
import com.gzh.teaching.model.vo.TopicParam;
import com.gzh.teaching.service.CommentService;
import com.gzh.teaching.service.dto.TopicOut;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/v1/api/mmt")
@RestController
public class CommentController {
  @Autowired
  private CommentService commentService;

  @PostMapping("/addTopic")
  @CheckToken
  public ResponseEntity<?> addTopic(@RequestBody TopicParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    commentService.addTopic(param.paramToIn(userId));
    return Result.ok();
  }

  @PostMapping("/delTopic")
  @CheckToken
  public ResponseEntity<?> delTopic(@RequestBody TopicParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    commentService.delTopic(param.paramToIn(userId));
    return Result.ok();
  }

  @PostMapping("/addComment")
  @CheckToken
  public ResponseEntity<?> addComment(@RequestBody CommentParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    commentService.addComment(param.paramToIn(userId));
    return Result.ok();
  }

  @PostMapping("/delComment")
  @CheckToken
  public ResponseEntity<?> delComment(@RequestBody CommentParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    commentService.delComment(param.paramToIn(userId));
    return Result.ok();
  }

  @PostMapping("/updateLike")
  @CheckToken
  public ResponseEntity<?> addLike(@RequestBody CommentParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    commentService.addLike(param.paramToIn(userId));
    return Result.ok();
  }

  @GetMapping("/queryTopic")
  @CheckToken
  public ResponseEntity<?> queryTopic( CommentParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    TopicOut out = commentService.queryTopic(param.paramToIn(userId));
    return Result.ok(out);
  }

  @GetMapping("/queryComment")
  @CheckToken
  public ResponseEntity<?> queryComment(CommentParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    CommentResult result = commentService.queryComment(param.paramToIn(userId));
    return Result.ok(result);
  }
}
